<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="题库分类">
              <ao-category-select placeholder="请选择题库分类" v-model="queryParam.categoryId" returnColumn="code"  pcode=""/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="题目信息">
              <a-input placeholder="请输入题目信息" v-model="queryParam.infoText"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="类型">
                <j-dict-select-tag placeholder="请选择类型" v-model="queryParam.type" dictCode="question_type"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="是否练习题">
                <j-dict-select-tag placeholder="请选择是否练习题" v-model="queryParam.isTest" dictCode="yn"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button v-has="'question:add'" @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button v-has="'question:export'" type="primary" icon="download" @click="handleExportXls('题目信息')">导出</a-button>
      <a-upload v-has="'question:import'" name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query> -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item v-has="'question:del'" key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        
        <!-- 字符串超长截取省略号显示-->
        <span slot="ellipsis" slot-scope="text">
          <j-ellipsis :value="text" :length="15"/>
        </span>

        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">详情</a>

          <a-divider v-has="'question:edit'" type="vertical" />
          <a v-has="'question:edit'" @click="handleEdit(record)">编辑</a>

          <a-divider v-has="'question:del'" type="vertical" />
          <a-popconfirm v-has="'question:del'" title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>

      </a-table>
    </div>

    <ao-question-modal ref="modalForm" @ok="modalFormOk"/>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import AoQuestionModal from './modules/AoQuestionModal'
  import { loadCategoryData } from '@/api/api'
  import JEllipsis from '@/components/jeecg/JEllipsis'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import '@/assets/less/TableExpand.less'

  export default {
    name: "AoQuestionList",
    mixins:[JeecgListMixin],
    components: {
      AoQuestionModal,
      JEllipsis
    },
    data () {
      return {
        description: '题目表管理页面',
        // 表头
        columns: [
          {
            title:'题库分类',
            align:"center",
            sorter: true,
            dataIndex: 'categoryId_dictText',
          },
          {
            title:'正确答案',
            align:"center",
            dataIndex: 'correct'
          },
          {
            title:'题目信息',
            align:"center",
            dataIndex: 'infoText',
            scopedSlots: { customRender: 'ellipsis' },
          },
          {
            title:'作答次数',
            align:"center",
            sorter: true,
            dataIndex: 'answerCount'
          },
          {
            title:'正确次数',
            align:"center",
            sorter: true,
            dataIndex: 'rightCount'
          },
          {
            title:'类型',
            align:"center",
            dataIndex: 'type_dictText'
          },
          {
            title:'是否练习题',
            align:"center",
            dataIndex: 'isTest_dictText'
          },
          {
            title:'录入人',
            align:"center",
            dataIndex: 'createBy_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/question/aoQuestion/list",
          delete: "/question/aoQuestion/delete",
          deleteBatch: "/question/aoQuestion/deleteBatch",
          exportXlsUrl: "/question/aoQuestion/exportXls",
          importExcelUrl: "question/aoQuestion/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig(){
        loadCategoryData({code:""}).then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'categoryId', res.result)
          }
        })
      },
      getSuperFieldList(){
        let fieldList=[];
         fieldList.push({type:'string',value:'categoryId',text:'科目编号'})
         fieldList.push({type:'string',value:'correct',text:'正确答案',dictCode:''})
         fieldList.push({type:'string',value:'infoText',text:'题目信息',dictCode:''})
         fieldList.push({type:'string',value:'analysis',text:'解析',dictCode:''})
         fieldList.push({type:'int',value:'answerCount',text:'作答次数',dictCode:''})
         fieldList.push({type:'int',value:'rightCount',text:'正确次数',dictCode:''})
         fieldList.push({type:'string',value:'type',text:'类型',dictCode:'question_type'})
         fieldList.push({type:'string',value:'isTest',text:'是否练习题',dictCode:'yn'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>